<template>
  <view class="cart-container">
    <my-address></my-address>
    <!-- 购物车商品列表的标题区域 -->
    <view class="cart-title">
      <!-- 左侧图标 -->
      <uni-icons type="shop" size="20"></uni-icons>
      <text class="cart-title-text">购物车</text>
    </view>
    <!-- 商品区域 -->
    <uni-swipe-action v-if="cart.length>0">
      <block v-for="(item,i) in cart" :key="i">
        <uni-swipe-action-item :right-options="options" @click="bindClick(item)">
          <my-goods :goods="item" :showRadio="true" @radio-change="radioChangeHandler" :showNum="true" @num-change="numberChangeHandler"></my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <view class="" v-else>
      暂时没有商品，快去
      <view style="display: flex;">
        <navigator @click="gotohome" style="color: lime;" open-type="switchTab">首页</navigator>看看吧
      </view>
    </view>
    <!-- 结算区域 -->
    <my-settle></my-settle>
  </view>
</template>

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
  import {mapState,mapMutations} from 'vuex'
  export default {
    mixins:[badgeMix],
    data() {
      return {
        options:[
          {
            text:'删除',
            style:{
              backgroundColor:'#C00000'
            }
          },
        ],
        CartList:[]
      }
    },
    onLaunch(options) {
      console.log(options);
    },
    computed:{
      ...mapState('m_cart',['cart'])
    },
    methods:{
      ...mapMutations('m_cart',['updateGoodsState','updateGoodsCount','removeGoodsById']),
      radioChangeHandler(e){
        //修改商品状态
        this.updateGoodsState(e)
      },
      numberChangeHandler(e){
        this.updateGoodsCount(e)
      },
      bindClick(e){
         console.log(e);
         this.removeGoodsById(e.goods_id)
      },
      gotohome(){
        uni.switchTab({
          url:'/pages/home/home'
        })
      }
    }
    
  }
</script>

<style lang="scss">
.cart-title{
  height: 40px;
  margin: 5px;
  display: flex;
  align-items: center;
  font-size: 14px;
    .cart-title-text{
      padding-left: 8px;
    }
}
.cart-container{
  padding-bottom: 50px;
}
</style>
